package org.springblade.application.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.application.command.ApplicationManagementPageCommand;
import org.springblade.application.service.IApplicationManagementService;
import org.springblade.applicationapi.entity.ApplicationManagementEntity;
import org.springblade.applicationapi.entity.TargetAddressEntity;
import org.springblade.applicationapi.vo.ApplicationManagementVO;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wzy
 * @date 2022/1/7
 */
@Slf4j
@AllArgsConstructor
@NoArgsConstructor
@RestController
@RequestMapping("application/application_management")
@Api(value = "应用管理",tags = "应用管理")
public class ApplicationManagementController extends BladeController {

	@Resource
	IApplicationManagementService service;

	/**
	 * 分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "分页", notes = "分页")
	public R<IPage<ApplicationManagementVO>> page(@ApiParam(value = "应用管理Command") ApplicationManagementPageCommand pageCommand, Query query) {
		IPage<ApplicationManagementVO> managementPage =
			service.managementPage(pageCommand, Condition.getPage(query));
		return R.data(managementPage);
	}


	/**
	 * 修改
	 */
	@PostMapping("/edit")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "修改", notes = "修改")
	public R<Object> edit(@ApiParam(value = "应用管理实体类") @RequestBody ApplicationManagementEntity entity)  {
		return R.status(service.edit(entity));
	}
	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "删除", notes = "删除")
	public R<Object> remove(@ApiParam(value = "应用管理表id")  @RequestParam(value = "id",required = false) List<Long> ids) {
		return R.status(service.removeByid(ids));
	}
	/**
	 * 权限配置
	 */
	@PostMapping("/addPermissions")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "权限配置", notes = "权限配置")
	public R<Object> addPermissions(@ApiParam(value = "应用管理表") @RequestBody ApplicationManagementEntity entity) {
		return R.data(service.addPermissions(entity));
	}



}
